home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 44.0 KB | 1,611 lines | [TEXT/MPS ] |
- {$P}
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n+]}
- { UDemoDialogs.inc1.p }
- { Copyright © 1988 - 1990 Apple Computer, Inc. All rights reserved. }
-
- {--------------------------------------------------------------------------------------------------}
-
- CONST
- kNoOfLines = 10000;
- kMaxScrollBar = 1000;
- kTestIcon = 1000;
- kTestAlert = 1000;
- kTestPopup = 235;
- kBaudPopup = 236;
- kParityPopup = 237;
- kTestPicture = 1000;
- kTestStatic = 1000;
- kMaxPlaces = 13;
-
- cFirstItem = 1001;
- cProcedureViews = 1001;
- cTemplateViews = 1002;
- cMonthlyDialog = 1003;
- cSaveDialog = 1004;
- cMarkDialog = 1005;
- cPageSetupDialog = 1006;
- cHomeBrewControls = 1007;
- cTabbingTest = 1008;
- cCalculator = 1009;
- cScrollingTest = 1011;
- cFormatDialog = 1012;
- cModelessMarkDialog = 1013;
- cLastItem = 1013;
- cPopupExample = 1100;
-
- mUpArrow = 100;
- mDownArrow = 101;
- mTemperatureChanged = 102;
-
- TYPE
- FondHandle = ^FondPointer;
- FondPointer = ^FondRecord;
- FondRecord = RECORD
- familyStuff: FamRec;
- noOfFonts: INTEGER;
- fontStuff: ARRAY [0..1000] OF RECORD
- size: INTEGER;
- style: INTEGER;
- resID: INTEGER;
- END;
- END;
-
-
- VAR
- gMonthlyValues: ARRAY [1..12] OF LONGINT;
- gMonthIDs: ARRAY [1..12] OF IDType;
-
-
- {******************************************************************************************}
- { T T e s t A p p l i c a t i o n }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
-
- {$S AInit}
- PROCEDURE TTestApplication.ITestApplication(itsMainFileType: OSType);
-
- VAR
- i: INTEGER;
- monthIDs: PACKED ARRAY [1..48] OF CHAR;
-
- BEGIN
- IApplication(itsMainFileType);
- fLaunchWithNewDocument := FALSE; { Suppress the creation of a new document at launch }
-
- FOR i := 1 TO 12 DO
- gMonthlyValues[i] := i * 100;
- monthIDs := 'jan feb mar apr may jun jul aug sep oct nov dec ';
- BlockMove(@monthIDs, @gMonthIDs, SIZEOF(gMonthIDs));
-
- { Suppress dead-stripping of the following classes }
- IF gDeadStripSuppression THEN
- BEGIN
- IF Member(TObject(NIL), TMonthlyDialog) THEN;
- IF Member(TObject(NIL), TArrowsControl) THEN;
- IF Member(TObject(NIL), TTemperatureCluster) THEN;
- IF Member(TObject(NIL), TTemperatureConversionCluster) THEN;
- IF Member(TObject(NIL), TSlider) THEN;
- IF Member(TObject(NIL), THomeBrewDialog) THEN;
- IF Member(TObject(NIL), TFontListView) THEN;
- IF Member(TObject(NIL), TSizeListView) THEN;
- IF Member(TObject(NIL), TRadioIcon) THEN;
- IF Member(TObject(NIL), TPageSetupDialog) THEN;
- IF Member(TObject(NIL), TSumStaticText) THEN;
- IF Member(TObject(NIL), TCalcDialog) THEN;
- IF Member(TObject(NIL), TNumbersView) THEN;
- IF Member(TObject(NIL), TModelessMarkDialog) THEN;
- IF Member(TObject(NIL), TScrollBar) THEN;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ASelCommand}
-
- FUNCTION TTestApplication.DoMenuCommand(aCmdNumber: CmdNumber): TCommand;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakeProcedureViews;
-
- VAR
- i: INTEGER;
- iStyle: StyleItem;
- oneStyle: Set OF StyleItem;
- aColor: RGBColor;
- itsLocation: VPoint;
- itsSize: VPoint;
- ts: TextStyle;
- aWindow: TWindow;
- aDialogView: TDialogView;
- aCluster: TCluster;
- aRadio: ARRAY [0..7] OF TRadio;
- aButton: TButton;
- anIcon: TIcon;
- aCheckBox: TCheckBox;
- aPopup: TPopup;
- aPicture: TPicture;
- aStaticText: TStaticText;
- anEditText: TEditText;
-
- BEGIN
- NEW(aDialogView);
- FailNIL(aDialogView);
- SetVPt(itsSize, 480, 900);
- aDialogView.IDialogView(NIL, NIL, gZeroVPt, itsSize, SizeFixed, SizeFixed,
- kNoIdentifier, kNoIdentifier);
- aDialogView.ParamTxt('^0', 'PARAM0');
- aDialogView.ParamTxt('^1', 'PARAM1');
-
- aWindow := NewSimpleWindow(aCmdNumber, TRUE, TRUE, NIL, aDialogView);
- aWindow.fFreeOnClosing := TRUE;
- aWindow.SimpleStagger(kStdStaggerAmount, kStdStaggerAmount, gStdStaggerCount);
-
- NEW(aStaticText);
- FailNIL(aStaticText);
- SetVPt(itsLocation, 50, 100);
- SetVPt(itsSize, 300, 150);
- aStaticText.IStaticText(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
- kTestStatic, 1);
- SetRGBColor(aColor, 0, 0, $FFFF);
- SetTextStyle(ts, applFont, [italic], 12, aColor);
- aStaticText.InstallTextStyle(ts, kDontRedraw);
- aStaticText.SetJustification(teJustCenter, kRedraw);
-
- NEW(aCluster);
- FailNIL(aCluster);
- SetVPt(itsLocation, 100, 340);
- SetVPt(itsSize, 150, 190);
- aCluster.ICluster(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
- kNoResource, 0);
- aCluster.SetLabel('A Cluster!', kRedraw);
-
- SetVPt(itsSize, 130, 20);
- oneStyle := []; { no styles = plain }
- iStyle := bold;
- FOR i := 0 TO 7 DO
- BEGIN
- NEW(aRadio[i]);
- FailNIL(aRadio[i]);
- SetVPt(itsLocation, 10, (i + 1) * 20);
- aRadio[i].IRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, '', i = 2);
- SetTextStyle(ts, systemFont, oneStyle, 12, gRGBBlack);
- aRadio[i].InstallTextStyle(ts, kDontRedraw);
- CASE i OF
- 0:
- aRadio[i].SetText('Plain', kRedraw);
- 1:
- aRadio[i].SetText('Bold', kRedraw);
- 2:
- aRadio[i].SetText('Italic', kRedraw);
- 3:
- aRadio[i].SetText('Underline', kRedraw);
- 4:
- aRadio[i].SetText('Outline', kRedraw);
- 5:
- aRadio[i].SetText('Shadow', kRedraw);
- 6:
- aRadio[i].SetText('Condense', kRedraw);
- 7:
- aRadio[i].SetText('Extend', kRedraw);
- END;
- oneStyle := [iStyle];
- iStyle := SUCC(iStyle);
- END;
-
- NEW(aCheckBox);
- FailNIL(aCheckBox);
- SetVPt(itsLocation, 100, 540);
- SetVPt(itsSize, 100, 20);
- aCheckBox.ICheckBox(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
- 'Check Box', FALSE);
- SetTextStyle(ts, applFont, [], 12, gRGBBlack);
- aCheckBox.InstallTextStyle(ts, kRedraw);
-
- NEW(aButton);
- FailNIL(aButton);
- SetVPt(itsLocation, 270, 540);
- SetVPt(itsSize, 100, 28);
- aButton.IButton(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
- 'Push Button');
- SetTextStyle(ts, applFont, [], 10, gRGBBlack);
- aButton.InstallTextStyle(ts, kDontRedraw);
- aButton.fAdornment := [adnRRect];
- aButton.fPenSize := Point($00030003);
- aButton.Inset(4, 4, kRedraw);
-
- NEW(anIcon);
- FailNIL(anIcon);
- SetVPt(itsLocation, 130, 570);
- SetVPt(itsSize, 35, 35);
- anIcon.IIcon(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable, kTestIcon,
- kPreferColor);
- anIcon.fAdornment := kFrame + [adnShadow];
- anIcon.ViewEnable(TRUE, kDontRedraw);
- anIcon.Inset(1, 1, kDontRedraw);
-
- IF qNeedsHierarchicalMenus | gConfiguration.hasHierarchicalMenus THEN
- BEGIN
- NEW(aPopup); { test popup }
- FailNIL(aPopup);
- SetVPt(itsLocation, 290, 589);
- SetVPt(itsSize, 120, 22);
- aPopup.IPopup(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable, kTestPopup,
- 2, 50);
-
- NEW(aPopup); { baud popup }
- FailNIL(aPopup);
- SetVPt(itsLocation, 290, 624);
- SetVPt(itsSize, 120, 22);
- aPopup.IPopup(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable, kBaudPopup,
- 1, 50);
-
- NEW(aPopup); { parity popup }
- FailNIL(aPopup);
- SetVPt(itsLocation, 290, 659);
- SetVPt(itsSize, 120, 22);
- aPopup.IPopup(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable, kParityPopup,
- 1, 50);
- END;
-
- NEW(aPicture);
- FailNIL(aPicture);
- SetVPt(itsLocation, 100, 660);
- SetVPt(itsSize, $18C - $F0 + 16, $12C - $8F + 16);
- aPicture.IPicture(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
- kTestPicture);
- aPicture.fPenSize := Point($00020002);
- aPicture.fAdornment := [adnRRect, adnShadow];
- aPicture.ViewEnable(TRUE, kDontRedraw);
- aPicture.Inset(8, 8, kDontRedraw);
-
- NEW(aStaticText);
- FailNIL(aStaticText);
- SetVPt(itsLocation, 20, 620);
- SetVPt(itsSize, 100, 20);
- aStaticText.IStaticText(aDialogView, itsLocation, itsSize, sizeVariable, sizeVariable,
- kTestStatic, 2);
- SetRGBColor(aColor, $FFFF, 0, 0);
- aStaticText.InstallColor(aColor, kRedraw);
-
- NEW(anEditText);
- FailNIL(anEditText);
- SetVPt(itsLocation, 140, 620);
- SetVPt(itsSize, 100, 22);
- anEditText.IEditText(aDialogView, itsLocation, itsSize, 255);
- SetTextStyle(ts, applFont, [], 12, gRGBBlack);
- anEditText.InstallTextStyle(ts, kDontRedraw);
- anEditText.SetJustification(teJustRight, kDontRedraw);
- anEditText.SetText('EditText', kRedraw);
-
- { aDialogView.DoSelectEditText(anEditText, TRUE); * select text and scroll it into view }
- aWindow.Open;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakeTemplateViews;
-
- VAR
- aWindow: TWindow;
- aDialogView: TDialogView;
- aPopup: TPopup;
-
- BEGIN
- aWindow := NewTemplateWindow(aCmdNumber, NIL);
- FailNIL(aWindow);
- aDialogView := TDialogView(aWindow.FindSubView('DLOG'));
- IF qNeedsHierarchicalMenus | gConfiguration.hasHierarchicalMenus THEN
- aPopup := TPopup(DoCreateViews(NIL, aDialogView, cPopupExample, gZeroVPt));
- aDialogView.ParamTxt('^0', 'PARAM0');
- aDialogView.ParamTxt('^1', 'PARAM1');
- aWindow.Open;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakeScrollingTest;
-
- VAR
- aWindow: TWindow;
- minSize: Point;
-
- BEGIN
- aWindow := NewTemplateWindow(aCmdNumber, NIL);
- FailNIL(aWindow);
- SetPt(minSize, 315, 260);
- aWindow.SetResizeLimits(minSize, aWindow.fResizeLimits.botRight);
- aWindow.Open;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakeMonthlyDialog;
-
- VAR
- aWindow: TWindow;
- aMonthlyDialog: TMonthlyDialog;
-
- BEGIN
- aWindow := NewTemplateWindow(aCmdNumber, NIL);
- FailNIL(aWindow);
- aMonthlyDialog := TMonthlyDialog(aWindow.FindSubView('DLOG'));
- IF aMonthlyDialog <> NIL THEN
- aMonthlyDialog.StuffValues;
- aWindow.Open;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakeSaveDialog;
-
- VAR
- aWindow: TWindow;
- dismisser: IDType;
-
- BEGIN
- aWindow := NewTemplateWindow(aCmdNumber, NIL);
- FailNIL(aWindow);
- dismisser := TDialogView(aWindow.FindSubView('DLOG')).PoseModally;
-
- {$IFC qDebug}
- IF dismisser = 'yes ' THEN
- WRITELN('The user said yes.')
- ELSE IF dismisser = 'no ' THEN
- WRITELN('The user said no.')
- ELSE IF dismisser = 'cncl' THEN
- WRITELN('The user cancelled the dialog.')
- ELSE
- WRITELN('I don''t know how the user responded');
- {$ENDC}
- aWindow.Close;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakeMarkDialog;
-
- VAR
- aWindow: TWindow;
- dismisser: IDType;
- {$IFC qDebug}
- theMark: Str255;
- {$ENDC}
-
- BEGIN
- aWindow := NewTemplateWindow(aCmdNumber, NIL);
- FailNIL(aWindow);
- dismisser := TDialogView(aWindow.FindSubView('DLOG')).PoseModally;
- {$IFC qDebug}
- IF dismisser = 'ok ' THEN
- BEGIN
- TEditText(aWindow.FindSubView('mark')).GetText(theMark);
- IF (theMark = '') THEN
- WRITELN('No mark specified.')
- ELSE
- WRITELN('The mark is ''', theMark, '''.');
- END
- ELSE
- WRITELN('The dialog was cancelled.');
- {$ENDC}
- aWindow.Close;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakeDialog;
-
- VAR
- aWindow: TWindow;
-
- BEGIN
- aWindow := NewTemplateWindow(aCmdNumber, NIL);
- FailNIL(aWindow);
- aWindow.Open;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakeFormatDialog;
-
- VAR
- aWindow: TWindow;
- theDialog: TDialogView;
- dismisser: IDType;
-
- {--------------------------------------------------------------------------------------------------}
- PROCEDURE SetupTheFontView;
-
- VAR
- theFontListView: TFontListView;
- theSizeListView: TSizeListView;
-
- BEGIN
- theSizeListView := TSizeListView(theDialog.FindSubView('slst'));
- theSizeListView.fSelection := 0;
- theSizeListView.fSelectedSize := 9;
- theFontListView := TFontListView(theDialog.FindSubView('flst'));
- theFontListView.InitFontList;
- theFontListView.SelectItem(1, kDontExtend, kHighlight, kSelect);
- END;
-
- BEGIN
- aWindow := NewTemplateWindow(aCmdNumber, NIL);
- FailNIL(aWindow);
- theDialog := TDialogView(aWindow.FindSubView('DLOG'));
- SetupTheFontView;
-
- dismisser := theDialog.PoseModally;
- {$IFC qDebug}
- IF dismisser <> 'ok ' THEN
- WRITELN('The dialog was cancelled.');
- {$ENDC}
- aWindow.Close;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakePageSetupDialog;
-
- VAR
- aWindow: TWindow;
- theDialog: TPageSetupDialog;
- dismisser: IDType;
- orientation: VHSelect;
-
- BEGIN
- aWindow := NewTemplateWindow(aCmdNumber, NIL);
- FailNIL(aWindow);
- theDialog := TPageSetupDialog(aWindow.FindSubView('DLOG'));
- orientation := v;
- theDialog.fOrientation := orientation;
- TRadioIcon(theDialog.FindSubView('vert')).HiliteState(orientation = v, kDontRedraw);
- TRadioIcon(theDialog.FindSubView('horz')).HiliteState(orientation = h, kDontRedraw);
-
- dismisser := theDialog.PoseModally;
- {$IFC qDebug}
- IF dismisser = 'ok ' THEN
- BEGIN
- END
- ELSE
- WRITELN('The dialog was cancelled.');
- {$ENDC}
- aWindow.Close;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE MakeCalculator;
-
- VAR
- aWindow: TWindow;
- aCalcDialog: TCalcDialog;
-
- BEGIN
- aWindow := NewTemplateWindow(aCmdNumber, NIL);
- FailNIL(aWindow);
- aCalcDialog := TCalcDialog(aWindow.FindSubView('DLOG'));
- aCalcDialog.ClearSum;
- aWindow.Open;
- END;
-
- BEGIN
- DoMenuCommand := NIL;
- CASE aCmdNumber OF
- cProcedureViews:
- MakeProcedureViews;
- cTemplateViews:
- MakeTemplateViews;
- cScrollingTest:
- MakeScrollingTest;
- cMonthlyDialog:
- MakeMonthlyDialog;
- cSaveDialog:
- MakeSaveDialog;
- cMarkDialog:
- MakeMarkDialog;
- cModelessMarkDialog:
- MakeDialog;
- cFormatDialog:
- MakeFormatDialog;
- cPageSetupDialog:
- MakePageSetupDialog;
- cHomeBrewControls:
- MakeDialog;
- cTabbingTest:
- MakeDialog;
- cCalculator:
- MakeCalculator;
- OTHERWISE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TTestApplication.DoSetupMenus; OVERRIDE;
-
- VAR
- i: INTEGER;
-
- BEGIN
- INHERITED DoSetupMenus;
-
- FOR i := cFirstItem TO cLastItem DO
- Enable(i, TRUE);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TTestApplication.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TTestApplication', NIL, bClass);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T N u m b e r s V i e w }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TNumbersView.Draw(area: Rect); OVERRIDE;
-
- VAR
- viewRect: VRect;
- i, firstLine, lastLine: LONGINT;
- vPt: VPoint;
- pt: Point;
- s: Str255;
-
- BEGIN
- QDToViewRect(area, viewRect);
- viewRect.right := viewRect.right - 1;
- viewRect.bottom := viewRect.bottom - 1;
- firstLine := (viewRect.top DIV 16) + 1;
- lastLine := (viewRect.bottom DIV 16) + 1;
- SetPortTextStyle(gSystemStyle);
- FOR i := firstLine TO lastLine DO
- BEGIN
- SetVPt(vPt, 0, i * 16);
- pt := ViewToQDPt(vPt);
- MoveTo(pt.h, pt.v);
- NumToString(i, s);
- DrawString(s);
- END;
-
- INHERITED Draw(area);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TNumbersView.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TNumbersView', NIL, bClass);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T M o n t h l y D i a l o g }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
- {$S AClose}
-
- PROCEDURE TMonthlyDialog.DismissDialog(dismisser: IDType); OVERRIDE;
-
- VAR
- i: INTEGER;
-
- BEGIN
- FOR i := 1 TO 12 DO
- gMonthlyValues[i] := TNumberText(FindSubView(gMonthIDs[i])).GetValue;
- INHERITED DismissDialog(dismisser);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- FUNCTION TMonthlyDialog.DoKeyCommand(ch: CHAR; aKeyCode: INTEGER;
- VAR info: EventInfo): TCommand; OVERRIDE;
-
- BEGIN
- { If option-tab is pressed, deselect the current edit text and leave nothing selected.
- This is for test puropses only. It is not part of the Macintosh user interface. }
- IF (ch = chTab) & (info.theOptionKey) THEN
- BEGIN
- DoSelectEditText(NIL, FALSE);
- DoKeyCommand := NIL;
- END
- ELSE
- DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TMonthlyDialog.StuffValues;
-
- VAR
- i: INTEGER;
-
- BEGIN
- FOR i := 1 TO 12 DO
- TNumberText(FindSubView(gMonthIDs[i])).SetValue(gMonthlyValues[i], kDontRedraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TMonthlyDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TMonthlyDialog', NIL, bClass);
- INHERITED Fields(DoToField);
- END;
-
- {**************************************************************************************************}
- { T M o d e l e s s M a r k D i a l o g }
- {**************************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TModelessMarkDialog.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
-
- {$IFC qDebug}
- VAR
- theMark: Str255;
- {$ENDC}
-
- BEGIN
- CASE itsChoice OF
- mDefaultKey, { This handles when user presses the
- 'return' key }
- mCancelKey, { This handles when user presses the 'esc'
- key }
- mButtonHit: { This handles clicking in 'OK' or 'Cancel'
- buttons }
- IF origView.fIdentifier = fDefaultItem THEN
- BEGIN
- {$IFC qDebug}
- TEditText(FindSubView('mark')).GetText(theMark);
- WRITELN('The mark is ‘', theMark, '’');
- {$ENDC}
- GetWindow.Close;
- END
- ELSE IF origView.fIdentifier = fCancelItem THEN
- GetWindow.Close;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TModelessMarkDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TModelessMarkDialog', NIL, bClass);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T F o n t L i s t V i e w }
- {******************************************************************************************}
-
- {$S AOpen}
- PROCEDURE TFontListView.InitFontList;
-
- VAR
- pFondIDs: FontListPtr;
- i: INTEGER;
- noOfFonds: INTEGER;
- aString: Str255;
-
- FUNCTION FondAfter(VAR fontName: Str255): INTEGER;
- { Find the FOND whose name follows fontName alphabetically, and return its id and name }
-
- VAR
- theFondResource: Handle;
- lastID: INTEGER;
- thisID: INTEGER;
- itsType: ResType;
- index: INTEGER;
- foundFOND: BOOLEAN;
- lastName: Str255;
- thisName: Str255;
-
- BEGIN
- lastID := 0;
- foundFOND := FALSE;
- lastName := '~~~~~~~~';
- FOR index := 1 to noOfFonds DO
- BEGIN
- theFondResource := GetIndResource('FOND', index);
- GetResInfo(theFondResource, thisID, itsType, thisName);
- IF (thisName > fontName) & (thisName < lastName) THEN
- BEGIN
- lastID := thisID;
- CopyStr255(thisName, @lastName);
- foundFOND := TRUE;
- END;
- END;
- IF foundFOND THEN
- CopyStr255(lastName, @fontName)
- ELSE { Skip duplicate FOND names }
- fontName := '';
- FondAfter := lastID;
- END;
-
- BEGIN
- fFontList := NIL;
- noOfFonds := CountResources('FOND');
- IF noOfFonds > kMaxFonds THEN
- noOfFonds := kMaxFonds;
- pFondIDs := FontListPtr(NewPermPtr(noOfFonds * sizeof(INTEGER)));
- FailNIL(pFondIDs);
-
- aString := ' ';
- FOR i := 1 TO noOfFonds DO
- BEGIN { put each FOND's id in the list… }
- pFondIDs^[i] := FondAfter(aString); { …in alphabetical order }
- IF length(aString) = 0 THEN { we finished early }
- BEGIN
- noOfFonds := i-1;
- LEAVE;
- END;
- END;
-
- fFontList := pFondIDs;
- InsRowLast(noOfFonds, 16);
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S AClose}
- PROCEDURE TFontListView.Free; OVERRIDE;
-
- BEGIN
- Ptr(fFontList) := DisposeIfPtr(fFontList);
-
- INHERITED Free;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TFontListView.GetItemText(anItem: INTEGER; VAR aString: Str255); OVERRIDE;
-
- VAR
- theFondResource: Handle;
- itsID: INTEGER;
- itsType: ResType;
-
- BEGIN
- theFondResource := GetResource('FOND', fFontList^[anItem]);
- GetResInfo(theFondResource, itsID, itsType, aString);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TFontListView.SelectItem(anItem: INTEGER; extendSelection, highlight,
- select: BOOLEAN); OVERRIDE;
-
- VAR
- aView: TView;
-
- BEGIN
- INHERITED SelectItem(anItem, extendSelection, highlight, select);
-
- IF select THEN
- BEGIN
- aView := GetWindow.FindSubView('slst');
- FailNIL(aView);
- TSizeListView(aView).InstallFontFamily(fFontList^[anItem]);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TFontListView.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TFontListView', NIL, bClass);
- DoToField('fFontList', @fFontList, bPointer);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T S i z e L i s t V i e w }
- {******************************************************************************************}
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TSizeListView.GetItemText(anItem: INTEGER; VAR aString: Str255); OVERRIDE;
-
- VAR
- noOfSizes: INTEGER;
- theFond: FondHandle;
- i: INTEGER;
-
- BEGIN
- theFond := FondHandle(GetResource('FOND', fFondID));
- noOfSizes := 0;
- FOR i := 0 TO theFond^^.noOfFonts DO
- BEGIN
- IF theFond^^.fontStuff[i].style = 0 THEN
- noOfSizes := noOfSizes + 1;
- IF noOfSizes = anItem THEN
- BEGIN
- NumToString(theFond^^.fontStuff[i].size, aString);
- EXIT(GetItemText);
- END;
- END;
- aString := '';
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S AOpen}
- PROCEDURE TSizeListView.InstallFontFamily(theFondID: INTEGER);
-
- VAR
- theFond: FondHandle;
- noOfSizes: INTEGER;
- i: INTEGER;
- sizeToSelect: INTEGER;
-
- BEGIN
- theFond := FondHandle(GetResource('FOND', theFondID));
- noOfSizes := 0;
- sizeToSelect := 0;
- FOR i := 0 TO theFond^^.noOfFonts DO
- IF theFond^^.fontStuff[i].style = 0 THEN
- BEGIN
- noOfSizes := noOfSizes + 1;
- IF theFond^^.fontStuff[i].size = fSelectedSize THEN
- sizeToSelect := noOfSizes;
- END;
- fFondID := theFondID;
- SetNumberOfItems(noOfSizes);
- SelectItem(sizeToSelect, kDontExtend, kDontHighlight, kSelect);
- ForceRedraw;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TSizeListView.SelectItem(anItem: INTEGER; extendSelection, highlight,
- select: BOOLEAN); OVERRIDE;
-
- VAR
- aString: Str255;
- theSizeView: TNumberText;
- fontSize: LONGINT;
-
- BEGIN
- INHERITED SelectItem(anItem, extendSelection, highlight, select);
-
- IF select AND (anItem <> 0) THEN
- BEGIN
- GetItemText(anItem, aString);
- theSizeView := TNumberText(GetWindow.FindSubView('size'));
- theSizeView.SetText(aString, kRedraw);
- theSizeView.SetSelection(0, MAXINT, kRedraw);
- StringToNum(aString, fontSize);
- fSelectedSize := fontSize;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TSizeListView.SetNumberOfItems(aNumber: INTEGER);
-
- BEGIN
- SelectItem(0, kDontExtend, kHighlight, kSelect);
-
- IF fNumOfRows > aNumber THEN
- BEGIN
- DelItemFirst(fNumOfRows - aNumber);
- END
- ELSE IF fNumOfRows < aNumber THEN
- BEGIN
- InsItemFirst(aNumber - fNumOfRows);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TSizeListView.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TSizeListView', NIL, bClass);
- DoToField('fSelection', @fSelection, bInteger);
- DoToField('fSelectedSize', @fSelectedSize, bInteger);
- DoToField('fFondID', @fFondID, bInteger);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T P a g e S e t u p D i a l o g }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TPageSetupDialog.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
-
- VAR
- newOrientation: VHSelect;
- tallAdjCheckBox: TCheckBox;
-
- BEGIN
- CASE itsChoice OF
- mIconHit:
- BEGIN
- IF origView.fIdentifier = 'vert' THEN
- newOrientation := v
- ELSE
- newOrientation := h;
- IF newOrientation <> fOrientation THEN
- BEGIN
- TRadioIcon(FindSubView('vert')).HiliteState(newOrientation = v, kRedraw);
- TRadioIcon(FindSubView('horz')).HiliteState(newOrientation = h, kRedraw);
- tallAdjCheckBox := TCheckBox(FindSubView('tall'));
- tallAdjCheckBox.DimState(newOrientation = h, kRedraw);
- tallAdjCheckBox.SetState(FALSE, kRedraw);
- fOrientation := newOrientation;
- END;
- END;
- OTHERWISE
- INHERITED DoChoice(origView, itsChoice);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TPageSetupDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TPageSetupDialog', NIL, bClass);
- DoToField('fOrientation', @fOrientation, bVHSelect);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T R a d i o I c o n }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- PROCEDURE TRadioIcon.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
- nextPoint: VPoint; mouseDidMove: BOOLEAN); OVERRIDE;
-
- BEGIN
- IF aTrackPhase = TrackPress THEN
- DoChoice(SELF, mIconHit);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TRadioIcon.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TRadioIcon', NIL, bClass);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T H o m e B r e w D i a l o g }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
- FUNCTION THomeBrewDialog.DoSetCursor(localPoint: Point; cursorRgn: RgnHandle): BOOLEAN; OVERRIDE;
-
- VAR
- theCursor: CursHandle;
- qdExtent: Rect;
-
- BEGIN
- theCursor := GetCursor(crossCursor);
- SetCursor(theCursor^^);
- GetQDExtent(qdExtent);
- RectRgn(cursorRgn, qdExtent);
- DoSetCursor := TRUE;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
- FUNCTION THomeBrewDialog.HandleCursor(theMouse: VPoint; cursorRgn: RgnHandle): TView; OVERRIDE;
-
- BEGIN
- IF Focus & DoSetCursor(ViewToQDPt(theMouse), cursorRgn) THEN
- HandleCursor := SELF
- ELSE
- HandleCursor := NIL;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE THomeBrewDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('THomeBrewDialog', NIL, bClass);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T A r r o w s C o n t r o l }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
-
- {$S AOpen}
- PROCEDURE TArrowsControl.IRes(itsDocument: TDocument; itsSuperView: TView;
- VAR itsParams: Ptr); OVERRIDE;
-
- BEGIN
- INHERITED IRes(itsDocument, itsSuperView, itsParams);
- fLastChange := 0;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TArrowsControl.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
- nextPoint: VPoint; mouseDidMove: BOOLEAN); OVERRIDE;
-
- BEGIN
- IF TickCount >= fLastChange + 5 THEN
- BEGIN
- fLastChange := TickCount;
- IF aTrackPhase = TrackPress THEN
- fLastChange := fLastChange + 10;
-
- IF ContainsMouse(nextPoint) THEN
- IF nextPoint.v <= fSize.v DIV 2 THEN
- DoChoice(SELF, mUpArrow)
- ELSE
- DoChoice(SELF, mDownArrow);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TArrowsControl.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TArrowsControl', NIL, bClass);
- DoToField('fLastChange', @fLastChange, bLongint);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { TTemperatureCluster }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TTemperatureCluster.DoChoice(origView : TView;itsChoice : INTEGER); OVERRIDE;
- VAR
- theNumberText: TNumberText;
- theNumber: LONGINT;
-
- BEGIN
- CASE itsChoice OF
- mUpArrow, mDownArrow:
- BEGIN
- theNumberText := TNumberText(FindSubView('Numb'));
- theNumber := theNumberText.GetValue;
- IF itsChoice = mUpArrow THEN
- theNumber := theNumber + 1
- ELSE
- theNumber := theNumber - 1;
- theNumberText.SetValue(theNumber, kRedraw);
- INHERITED DoChoice(SELF,mTemperatureChanged);
- END;
- OTHERWISE
- INHERITED DoChoice(origView, itsChoice);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- FUNCTION TTemperatureCluster.GetValue: LONGINT;
- VAR numberText : TNumberText;
- BEGIN
- numberText := TNumberText(SELF.FindSubView('Numb'));
- GetValue := numberText.GetValue;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TTemperatureCluster.SetValue(newValue: LONGINT;
- redraw: BOOLEAN);
- VAR numberText : TNumberText;
- BEGIN
- numberText := TNumberText(SELF.FindSubView('Numb'));
- numberText.SetValue(newValue,redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TTemperatureCluster.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TTemperatureCluster', NIL, bClass);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { TTemperatureConversionCluster }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TTemperatureConversionCluster.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
-
- VAR
- Celsius, Fahrenheit: TTemperatureCluster;
-
- BEGIN
- IF itsChoice = mTemperatureChanged THEN
- BEGIN
- Celsius := TTemperatureCluster(FindSubView('Cels'));
- Fahrenheit := TTemperatureCluster(FindSubView('Fahr'));
- IF origView = Celsius THEN
- Fahrenheit.SetValue(TRUNC(Celsius.GetValue * 1.8 + 32), kRedraw)
- ELSE IF origView = Fahrenheit THEN
- Celsius.SetValue(TRUNC((Fahrenheit.GetValue - 32) / 1.8), kRedraw)
- END
- ELSE
- INHERITED DoChoice(origView, itsChoice);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TTemperatureConversionCluster.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TTemperatureConversionCluster', NIL, bClass);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T S l i d e r }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
-
- {$S AOpen}
- PROCEDURE TSlider.IRes(itsDocument: TDocument; itsSuperView: TView; VAR itsParams: Ptr); OVERRIDE;
-
- VAR
- knobPicture: PicHandle;
- knobRect: Rect;
-
- BEGIN
- INHERITED IRes(NIL, itsSuperView, itsParams);
- knobPicture := GetPicture(1002);
- fKnobPicture := knobPicture;
- WITH knobPicture^^.picFrame DO
- BEGIN
- SetPt(knobRect.topLeft, fSize.h - (right - left), fSize.v - 16);
- knobRect.right := knobRect.left + right - left;
- knobRect.bottom := knobRect.top + bottom - top;
- END;
- fMaxTop := knobRect.top;
- fMinTop := knobRect.top - 84;
- fKnobRect := knobRect;
- fValue := 0;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- FUNCTION TSlider.ContainsMouse(theMouse: VPoint): BOOLEAN; OVERRIDE;
-
- VAR
- knobRect: Rect;
-
- BEGIN
- GetKnobRect(knobRect);
- ContainsMouse := PtInRect(VPtToPt(theMouse), knobRect);
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TSlider.Draw(area: Rect); OVERRIDE;
-
- BEGIN
- INHERITED Draw(area); { This draws everything but the knob }
- DrawKnob;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TSlider.DrawKnob;
-
- VAR
- knobRect: Rect;
-
- BEGIN
- GetKnobRect(knobRect);
- LoadResource(Handle(fKnobPicture)); { In case it was purged from memory }
- DrawPicture(fKnobPicture, knobRect);
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TSlider.GetKnobRect(VAR knobRect: Rect);
-
- BEGIN
- knobRect := fKnobRect;
- OffsetRect(knobRect, 0, - (fValue * 12));
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TSlider.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
- nextPoint: VPoint; mouseDidMove: BOOLEAN); OVERRIDE;
-
- VAR
- oldRect: Rect;
- newRect: Rect;
- difference: Rect;
- savedClip: RgnHandle;
- base: INTEGER;
- offset: INTEGER;
-
- BEGIN
- GetKnobRect(oldRect);
- newRect := oldRect;
-
- { Compute rectangle of knob's current position }
- offset := Min(Max(previousPoint.v - anchorPoint.v, fMinTop - newRect.top), fMaxTop -
- newRect.top);
- OffsetRect(oldRect, 0, offset);
-
- { Compute rectangle of knob's new position }
- offset := Min(Max(nextPoint.v - anchorPoint.v, fMinTop - newRect.top), fMaxTop - newRect.top);
- OffsetRect(newRect, 0, offset);
-
- { If the mouse was release, pin the knob to a value and set slider's value }
- IF aTrackPhase = TrackRelease THEN
- BEGIN
- base := fSize.v - 16 - newRect.top;
- offset := base - ((base + 6) DIV 12 * 12);
- OffsetRect(newRect, 0, offset);
- fValue := (fSize.v - 16 - newRect.top) DIV 12;
- END;
-
- { To redraw minimal amount, compute difference between old and new positions }
- difference := oldRect;
- IF oldRect.top > newRect.top THEN
- difference.top := Max(oldRect.top, newRect.bottom)
- ELSE
- difference.bottom := Min(oldRect.bottom, newRect.top);
-
- savedClip := NewRgn;
- FailNIL(savedClip);
- GetClip(savedClip);
-
- ClipRect(difference);
- INHERITED Draw(difference);
-
- SetClip(savedClip);
- DisposeRgn(savedClip);
-
- LoadResource(Handle(fKnobPicture)); { In case it was purged from memory }
- DrawPicture(fKnobPicture, newRect);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TSlider.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TSlider', NIL, bClass);
- DoToField('fValue', @fValue, bInteger);
- DoToField('fKnobPicture', @fKnobPicture, bHandle);
- DoToField('fKnobRect', @fKnobRect, bRect);
- DoToField('fMinTop', @fMinTop, bInteger);
- DoToField('fMaxTop', @fMaxTop, bInteger);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T S u m S t a t i c T e x t }
- {******************************************************************************************}
-
- {$S ARes}
- PROCEDURE TSumStaticText.Draw(area: Rect); OVERRIDE;
-
- VAR
- theRect: Rect;
-
- BEGIN
- { Make sure the gray background gets completely erased }
- GetQDExtent(theRect);
- InsetRect(theRect, fPenSize.h, fPenSize.v);
- EraseRect(theRect);
- INHERITED Draw(area);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TSumStaticText.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TSumStaticText', NIL, bClass);
- INHERITED Fields(DoToField);
- END;
-
- {******************************************************************************************}
- { T C a l c D i a l o g }
- {******************************************************************************************}
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TCalcDialog.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
-
- VAR
- origID: IDType;
-
- BEGIN
- origID := origView.fIdentifier;
- CASE itsChoice OF
- mOKHit:
- CASE origID[4] OF
- 'C':
- ClearSum;
- '=', 'E':
- TotalSum(noOperator);
- '/':
- TotalSum(divOperator);
- '*':
- TotalSum(mulOperator);
- '-':
- TotalSum(subOperator);
- '+':
- TotalSum(addOperator);
- OTHERWISE
- NewDigit(origID[4]);
- END;
- OTHERWISE
- INHERITED DoChoice(origView, itsChoice);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- FUNCTION TCalcDialog.DoKeyCommand(ch: CHAR; aKeyCode: INTEGER;
- VAR info: EventInfo): TCommand; OVERRIDE;
-
- VAR
- foundIt: BOOLEAN;
- whoCares: LONGINT;
- theID: IDType;
- theView: TView;
-
- BEGIN
- foundIt := TRUE;
- IF aKeyCode = $47 THEN { Clear key }
- theID := 'keyC'
- ELSE IF (ch = chEnter) | (ch = chReturn) THEN
- theID := 'keyE'
- ELSE
- CASE ch OF
- '0'..'9', '.', '+', '-', '*', '/', '=':
- BEGIN
- theID := 'key ';
- theID[4] := ch;
- END;
- OTHERWISE
- BEGIN
- foundIt := FALSE;
- SysBeep(1);
- END;
- END;
- IF foundIt THEN
- BEGIN
- theView := FindSubView(theID);
- IF theView.Focus THEN
- BEGIN
- TControl(theView).Hilite;
- Delay(5, whoCares);
- TControl(theView).Hilite;
- END;
- DoChoice(theView, mOKHit);
- END;
- DoKeyCommand := NIL;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TCalcDialog.ClearSum;
-
- BEGIN
- fArgument := 0;
- fSum := 0;
- fOperator := noOperator;
- fDecimalPoint := FALSE;
- fRestart := TRUE;
- TStaticText(FindSubView('SUMM')).SetText('0', TRUE);
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TCalcDialog.FetchValue(VAR aValue: Extended);
-
- VAR
- theStr: Str255;
-
- BEGIN
- TStaticText(FindSubView('SUMM')).GetText(theStr);
- aValue := Str2Num(theStr);
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TCalcDialog.SetValue;
-
- VAR
- thePos: INTEGER;
- theStr: Str255;
- theForm: DecForm;
- anExtended: Extended;
-
- {--------------------------------------------------------------------------------------------------}
- PROCEDURE Truncate;
-
- VAR
- theChar: CHAR;
-
- BEGIN
- IF LENGTH(theStr) > 1 THEN
- BEGIN
- theChar := theStr[LENGTH(theStr)];
- IF (theChar = '0') | (theChar = '.') THEN
- Delete(theStr, LENGTH(theStr), 1);
- IF theChar = '0' THEN
- Truncate;
- END;
- END;
-
- BEGIN
- theForm.style := FixedDecimal;
- theForm.Digits := 2 * kMaxPlaces;
- anExtended := fSum;
- Num2Str(theForm, anExtended, DecStr(theStr));
- thePos := POS('.', theStr);
- IF thePos <> 0 THEN
- Truncate;
- IF (thePos > kMaxPlaces) | ((thePos <> 0) & (POS('000000', theStr) = thePos + 1)) THEN
- BEGIN
- theForm.style := FloatDecimal;
- theForm.Digits := 2;
- anExtended := fSum;
- Num2Str(theForm, anExtended, DecStr(theStr));
- END;
- IF LENGTH(theStr) > kMaxPlaces THEN
- theStr[0] := CHR(kMaxPlaces);
- TStaticText(FindSubView('SUMM')).SetText(theStr, TRUE);
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TCalcDialog.TotalSum(newOperator: CalcOperator);
-
- VAR
- aValue: Extended;
- BEGIN
- FetchValue(aValue);
- fArgument := aValue;
- CASE fOperator OF
- noOperator:
- fSum := fArgument;
- divOperator:
- fSum := fSum / fArgument;
- mulOperator:
- fSum := fSum * fArgument;
- subOperator:
- fSum := fSum - fArgument;
- addOperator:
- fSum := fSum + fArgument;
- END;
- SetValue;
- fRestart := TRUE;
- fArgument := fSum;
- fOperator := newOperator;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S ARes}
- PROCEDURE TCalcDialog.NewDigit(theNumber: CHAR);
-
- VAR
- theText: TStaticText;
- theStr: Str255;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE SetIt;
-
- BEGIN
- theStr[LENGTH(theStr) + 1] := theNumber;
- theStr[0] := CHR(LENGTH(theStr) + 1);
- theText.SetText(theStr, TRUE);
- END;
-
- BEGIN
- theText := TStaticText(FindSubView('SUMM'));
- IF fRestart THEN
- theStr := ''
- ELSE
- theText.GetText(theStr);
-
- IF LENGTH(theStr) < kMaxPlaces THEN
- BEGIN
- fRestart := FALSE;
- IF (theNumber = '.') AND NOT fDecimalPoint THEN
- fDecimalPoint := TRUE;
- SetIt;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- {$S AFields}
-
- PROCEDURE TCalcDialog.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TCalcDialog', NIL, bClass);
- DoToField('fSum', @fSum, bExtended);
- DoToField('fArgument', @fArgument, bExtended);
- DoToField('fOperator', @fOperator, bInteger);
- DoToField('fDecimalPoint', @fDecimalPoint, bBoolean);
- DoToField('fRestart', @fRestart, bBoolean);
- INHERITED Fields(DoToField);
- END;
-